/**
 * (C) 2007 - 2009 Parleys.com NV.
 */
package com.parleys.api.resource;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;

import com.parleys.api.annotation.Resource;
import com.parleys.core.domain.Space;
import com.parleys.core.service.SpaceService;

/**
 * 
 * @author berkay
 *
 */
@Resource
@Path("/spaces")
public class SpaceResource
{

    @Autowired
    private SpaceService spaceService;

    @GET
    @Produces( { MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
    public List<Space> getSpaces(@QueryParam("from") @DefaultValue("0") final int from, @QueryParam("to") @DefaultValue("0") final int to)
    {
        // dummy database limits =)
        Collection<Space> spaces = spaceService.getSpaces();
        return new ArrayList<Space>(spaces).subList(from, to != 0 ? to : spaces.size());
    }

    @GET
    @Path("auth")
    public String getHeader(@HeaderParam("auth") String auth)
    {
        return auth;
    }

}
